package com.tandashi.springbootstudy01.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
@Order(2)
@Slf4j
public class CommonConfig {

    @Bean
    ScheduledExecutorService scheduledExecutorService() {
        int core = Math.max(8, Runtime.getRuntime().availableProcessors()) + 1;
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(core);
        executor.setKeepAliveTime(1L, TimeUnit.MINUTES);
        executor.allowCoreThreadTimeOut(true);
        return executor;
    }
}
